/**
 * tigerrad
 * fall 2006
 */

#ifndef _RENDERBUFFER_H
#define _RENDERBUFFER_H

#include "Util.h"
#include "Texture.h"

/**
 * Abstracts a Render Buffer.  
 */
class Renderbuffer
{
	public:
		/**
		 * Constructor.
		 * @param name Debug name(id)
		 * @param size Size of the render Buffer
		 */
		Renderbuffer(const std::string& name, const Vec2s& size,
                     GLenum target, GLenum intFormat) :
			_name(name), _size(size), _target(target), _intFormat(intFormat)
		{
			glGenRenderbuffersEXT(1, &_glName);
			// TODO umm...is this ever unbound?
            glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, _glName);
            glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, _intFormat, _size[0], _size[1]);
		}
	
		/**
		 * Return the debug name.
		 */
		std::string getName() const { return _name; }

		/**
		 * Return the Texture size (width, height);
		 */
		Vec2s getSize() const { return _size; }

		/**
		 * Return the Texture target.
		 */
		GLenum getTarget() const { return _target; } 

		/**
		 * Return the Texture internal format.
		 */
		GLenum getInternalFormat() const { return _intFormat; }

		/**
		 * Return the OpenGL Texture name.
		 */
		GLuint getGLName() const { return _glName; }
	
		/**
		 * Destructor.
		 */
		Renderbuffer() 
		{
		}
		
	private:

		std::string _name;
		Vec2s _size;
		GLenum _target;
		GLenum _intFormat;
		GLuint _glName;

};

typedef boost::shared_ptr<Renderbuffer> RenderbufferPtr;

#endif

